package de.fhb.itunes.manager.Datenverwaltung;

import java.util.List;

import de.fhb.itunes.repository.DataAccess.DAO_Album;
import de.fhb.itunes.repository.DataAccess.IDAO_Album;
import de.fhb.itunes.repository.data.Album_VO;

public class Albenverwaltung {
	private IDAO_Album alben = new DAO_Album();
	private List<Album_VO> all = null;


	public void setAll(List<Album_VO> all) {
		this.all = all;
	}

	private static Albenverwaltung instanceOfItSelf;

	private Albenverwaltung() {
		super();
	}

	public static Albenverwaltung getInstance() {
		if (instanceOfItSelf == null) {
			instanceOfItSelf = new Albenverwaltung();
		}
		return instanceOfItSelf;
	}

	public List<Album_VO> getAll() {
		if (all != null) {
			Thread th;
		     Thread.UncaughtExceptionHandler eh = new Thread.UncaughtExceptionHandler() {
		       public void uncaughtException(Thread t, Throwable e) {
		         e.printStackTrace();
		       }
		     }; 
		     th = new Thread(new AlbenAktualisierer()); 
			th.setUncaughtExceptionHandler(eh);
			th.start();
			return all;
		} else {
			all = alben.getall();
			return all;
		}
	}

	public List<Album_VO> getbyAlbumname(String albumname) {
		return alben.getbyAlbumname(albumname);
	}

	public Album_VO getbyAlbumnameAndAlbumInterpet(String albumname,
			String albuminterpret) {
		return alben.getbyAlbumnameAndAlbumInterpet(albumname, albuminterpret);
	}
	public List<Album_VO> searchbyKeyword(String keyword){
		return alben.searchbyKeyword(keyword);
	}

}
